home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / guile-ii.src / guile-ii / guile-src / goonix / unix.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-02  |  4.9 KB  |  203 lines

  1. /*    Copyright (C) 1995 Free Software Foundation, Inc.
  2.  * 
  3.  * This program is free software; you can redistribute it and/or modify
  4.  * it under the terms of the GNU General Public License as published by
  5.  * the Free Software Foundation; either version 2, or (at your option)
  6.  * any later version.
  7.  * 
  8.  * This program is distributed in the hope that it will be useful,
  9.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.  * GNU General Public License for more details.
  12.  * 
  13.  * You should have received a copy of the GNU General Public License
  14.  * along with this software; see the file COPYING.  If not, write to
  15.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  16.  *
  17.  * As a special exception, the Free Software Foundation gives permission
  18.  * for additional uses of the text contained in its release of GUILE.
  19.  *
  20.  * The exception is that, if you link the GUILE library with other files
  21.  * to produce an executable, this does not by itself cause the
  22.  * resulting executable to be covered by the GNU General Public License.
  23.  * Your use of that executable is in no way restricted on account of
  24.  * linking the GUILE library code into it.
  25.  *
  26.  * This exception does not however invalidate any other reasons why
  27.  * the executable file might be covered by the GNU General Public License.
  28.  *
  29.  * This exception applies only to the code released by the
  30.  * Free Software Foundation under the name GUILE.  If you copy
  31.  * code from other Free Software Foundation releases into a copy of
  32.  * GUILE, as the General Public License permits, the exception does
  33.  * not apply to the code that you add in this way.  To avoid misleading
  34.  * anyone as to the status of such modified files, you must delete
  35.  * this exception notice from them.
  36.  *
  37.  * If you write modifications of your own for GUILE, it is your choice
  38.  * whether to permit this exception to apply to your modifications.
  39.  * If you do not wish that, delete this exception notice.  
  40.  */
  41.  
  42.  
  43. #include <stdio.h>
  44. #include "_scm.h"
  45. #include "unix.h"
  46. #include <pwd.h>
  47. #include <sys/types.h>
  48. #include <sys/stat.h>
  49.  
  50. SCM scm_stat2scm P((struct stat *stat_temp));
  51.  
  52.  
  53. PROC (s_sys_mknod, "%mknod", 3, 0, 0, scm_sys_mknod);
  54. #ifdef __STDC__
  55. SCM
  56. scm_sys_mknod(SCM path, SCM mode, SCM dev)
  57. #else
  58. SCM
  59. scm_sys_mknod(path, mode, dev)
  60.      SCM path;
  61.      SCM mode;
  62.      SCM dev;
  63. #endif
  64. {
  65.   int val;
  66.   ASSERT(NIMP(path) && STRINGP(path), path, ARG1, s_sys_mknod);
  67.   ASSERT(INUMP(mode), mode, ARG2, s_sys_mknod);
  68.   ASSERT(INUMP(dev), dev, ARG3, s_sys_mknod);
  69.   SYSCALL(val = mknod(CHARS(path), INUM(mode), INUM(dev)));
  70.   return val ? BOOL_F : BOOL_T;
  71. }
  72.  
  73.  
  74. PROC (s_sys_acct, "%acct", 1, 0, 0, scm_sys_acct);
  75. #ifdef __STDC__
  76. SCM
  77. scm_sys_acct(SCM path)
  78. #else
  79. SCM
  80. scm_sys_acct(path)
  81.      SCM path;
  82. #endif
  83. {
  84.   int val;
  85.   if (FALSEP(path))
  86.     {
  87.       SYSCALL(val = acct(0););
  88.       return val ? BOOL_F : BOOL_T;
  89.     }
  90.   ASSERT(NIMP(path) && STRINGP(path), path, ARG1, s_sys_acct);
  91.   SYSCALL(val = acct(CHARS(path)));
  92.   return val ? BOOL_F : BOOL_T;
  93. }
  94.  
  95.  
  96. PROC (s_sys_nice, "%nice", 1, 0, 0, scm_sys_nice);
  97. #ifdef __STDC__
  98. SCM
  99. scm_sys_nice(SCM incr)
  100. #else
  101. SCM
  102. scm_sys_nice(incr)
  103.      SCM incr;
  104. #endif
  105. {
  106.   ASSERT(INUMP(incr), incr, ARG1, s_sys_nice);
  107.   return nice(INUM(incr)) ? BOOL_F : BOOL_T;
  108. }
  109.  
  110.  
  111. PROC (s_sync, "sync", 0, 0, 0, scm_sync);
  112. #ifdef __STDC__
  113. SCM
  114. scm_sync(void)
  115. #else
  116. SCM
  117. scm_sync()
  118. #endif
  119. {
  120.   sync();
  121.   return UNSPECIFIED;
  122. }
  123.  
  124.  
  125. PROC (s_sys_symlink, "%symlink", 2, 0, 0, scm_sys_symlink);
  126. #ifdef __STDC__
  127. SCM
  128. scm_sys_symlink(SCM oldpath, SCM newpath)
  129. #else
  130. SCM
  131. scm_sys_symlink(oldpath, newpath)
  132.      SCM oldpath;
  133.      SCM newpath;
  134. #endif
  135. {
  136.   int val;
  137.   ASSERT(NIMP(oldpath) && STRINGP(oldpath), oldpath, ARG1, s_sys_symlink);
  138.   ASSERT(NIMP(newpath) && STRINGP(newpath), newpath, ARG2, s_sys_symlink);
  139.   SYSCALL(val = symlink(CHARS(oldpath), CHARS(newpath)));
  140.   return val ? BOOL_F : BOOL_T;
  141. }
  142.  
  143.  
  144. PROC (s_sys_readlink, "%readlink", 1, 0, 0, scm_sys_readlink);
  145. #ifdef __STDC__
  146. SCM
  147. scm_sys_readlink(SCM path)
  148. #else
  149. SCM
  150. scm_sys_readlink(path)
  151.   SCM path;
  152. #endif
  153. {
  154.   sizet rv;
  155.   sizet size = 100;
  156.   char *buf;
  157.   SCM result = BOOL_F;
  158.   ASSERT (NIMP (path) && STRINGP (path),  path, (char *) ARG1, s_sys_readlink);
  159.   DEFER_INTS;
  160.   buf = scm_must_malloc (size, s_sys_readlink);
  161.   while ((rv = readlink (CHARS (path), buf, (sizet) size)) == size)
  162.     {
  163.       scm_must_free (buf);
  164.       size *= 2;
  165.       buf = scm_must_malloc (size, s_sys_readlink);
  166.     }
  167.   if (rv != -1)
  168.     result = scm_makfromstr (buf, rv, 0);
  169.   scm_must_free (buf);
  170.   ALLOW_INTS;
  171.   return result;
  172. }
  173.  
  174.  
  175. PROC (s_sys_lstat, "%lstat", 1, 0, 0, scm_sys_lstat);
  176. #ifdef __STDC__
  177. SCM
  178. scm_sys_lstat(SCM str)
  179. #else
  180. SCM
  181. scm_sys_lstat(str)
  182.   SCM str;
  183. #endif
  184. {
  185.   int i;
  186.   struct stat stat_temp;
  187.   ASSERT(NIMP(str) && STRINGP(str), str, (char *)ARG1, s_sys_lstat);
  188.   SYSCALL(i = lstat(CHARS(str), &stat_temp));
  189.   return i ? BOOL_F :  scm_stat2scm(&stat_temp);
  190. }
  191.  
  192. #ifdef __STDC__
  193. void
  194. scm_init_unix (void)
  195. #else
  196. void
  197. scm_init_unix ()
  198. #endif
  199. {
  200. #include "unix.x"
  201.     scm_add_feature ("unix");
  202. }
  203.